#pragma once
#include <Windows.h>
#include <string.h>
#include <WinInet.h>
#pragma comment(lib, "Wininet.lib")

typedef struct _HttpData
{
	LPVOID	header;
	LPVOID	data;
}HttpData, *PHttpData;

class HttpService
{
public:
	HttpService();
	~HttpService();

	BOOL init(LPCTSTR lpszAgent = "WinInetGet/0.1", LPCTSTR lpszProxyName = NULL, LPCTSTR lpszProxyByPass = NULL);
	BOOL connect(LPCTSTR lpszServerName, INTERNET_PORT nServerPort, LPCTSTR lpszUserName = NULL, LPCTSTR lpszPassword = NULL);
	BOOL ConnectAndCreateRequest(LPCTSTR lpszVerb, LPCTSTR lpszObjectName, DWORD nServerPort = 80, LPCTSTR lpszVersion = "HTTP/1.1", DWORD dwFlag = INTERNET_FLAG_NO_CACHE_WRITE);
	BOOL CreateRequest(LPCTSTR lpszVerb, LPCTSTR lpszObjectName, LPCTSTR lpszVersion = "HTTP/1.1", DWORD dwFlag = INTERNET_FLAG_NO_CACHE_WRITE);
	BOOL AddHeader(LPCTSTR lpszHeaders);
	BOOL SendRequest(LPCTSTR lpszHeaders = NULL, DWORD dwHeadersLength = 0, LPVOID lpOptional = 0, DWORD dwOptionalLength = 0);
	BOOL SendData(LPCVOID lpBuffer, DWORD dwNumberOfBytesToWrite);
	const PHttpData RecvData();
	void RecvData(LPSTR buf, DWORD size);
	void RecvDataWithHeader(LPSTR buf, DWORD size);
	void CloseRequest();

private:
	HINTERNET	m_hInternet;
	HINTERNET	m_hSession;
	HINTERNET	m_hRequest;
	HttpData	m_data;
};